<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

class FtpBase extends Base {
	var $host;
	var $user;
	var $password;
	var $path;
	var $port = 21;
	var $ssl = 0;
	var $silent = 0;
	
	//constructor
	function FtpBase() {
		
	}
	
	function set($host, $user, $password, $path, $port, $ssl = 0, $silent = 0) {
		
	}
	
	//
	function connect() {
		
	}
	
	function close() {
		return ftp_close($ftp_stream);
	}
	
	function mkd() {
		
	}
	
	function rmd() {
		
	}
	
	//
	function error($error) {
		$this->_error[] = $error;
	}
	
	//
	function dconnect($ftphost, $ftpuser, $ftppass, $ftppath, $ftpport = 21, $ftpssl = 0, $silent = 0) {
		global $ftp;
		@set_time_limit(0);
		
		$ftphost = wipespecial($ftphost);
		$ftpport = intval($ftpport);
		$ftpssl = intval($ftpssl);
		$ftp['timeout'] = intval($ftp['timeout']);
		
		$func = $ftpssl && function_exists('ftp_ssl_connect') ? 'ftp_ssl_connect' : 'ftp_connect';
		if( $func == 'ftp_connect' && !function_exists('ftp_connect')) {
			if( $silent) {
				return -4;
			} else {
				errorlog('FTP', "FTP not supported.", 0);
			}
		}
		if( $ftp_conn_id = @$func($ftphost, $ftpport, 20)) {
			if( $ftp['timeout'] && function_exists('ftp_set_option')) {
				@ftp_set_option($ftp_conn_id, FTP_TIMEOUT_SEC, $ftp['timeout']);
			}
			if($this->login($ftp_conn_id, $ftpuser, $ftppass)) {
				if( $ftp['pasv'] ) {
					$this->pasv($ftp_conn_id, TRUE);
				}
				if($this->chdir($ftp_conn_id, $ftppath)) {
					return $ftp_conn_id;
				} else {
					if( $silent) {
						return -3;
					} else {
						errorlog('FTP', "Chdir '$ftppath' error.", 0);
					}
				}
			} else {
				if( $silent) {
					return -2;
				} else {
					errorlog('FTP', '530 Not logged in.', 0);
				}
			}
		} else {
			if( $silent) {
				return -1;
			} else {
				errorlog('FTP', "Couldn't connect to $ftphost:$ftpport.", 0);
			}
		}
		$this->close($ftp_conn_id);
		
		return -1;
	}
}
//
?>